package com.school.test.service.impl;


import com.school.common.core.exception.ServiceException;
import com.school.test.domain.StatisticsVisit;
import com.school.test.domain.Websiteinfo;
import com.school.test.domain.vo.ParamsVo;
import com.school.test.mapper.StatisticsVisitMapper;
import com.school.test.mapper.WebsiteInfoMapper;
import com.school.test.service.WebsiteinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


@Service
public class WebsiteInfoServiceImpl implements WebsiteinfoService {

    @Autowired
    private WebsiteInfoMapper websiteInfoMapper;



    @Override
    public List<Websiteinfo> selectInfo(ParamsVo paramsVo) {

        List<Websiteinfo> websiteinfosList = websiteInfoMapper.selectInfo(paramsVo);
        if(CollectionUtils.isEmpty(websiteinfosList)){
            websiteinfosList = new ArrayList<>();
        }
        return websiteinfosList;
    }


    @Override
    public int deleteWebsiteInfoByIds(String id) {
        Websiteinfo websiteinfo = websiteInfoMapper.selectWebsiteInfoById(id);
        if(null == websiteinfo){
            throw new ServiceException(String.format("无法查询到网站数据"));
        }
        int num = websiteInfoMapper.deleteWebsiteInfoById(id);
        return num;
    }


    @Override
    public List<Websiteinfo> selectInfoByCompanyType(String type, String source) {

        List<Websiteinfo> websiteinfoList = websiteInfoMapper.selectWebsiteInfoByType(type,source);
        if(CollectionUtils.isEmpty(websiteinfoList)){
            websiteinfoList = new ArrayList<>();
        }
        return websiteinfoList;
    }

    @Override
    public int addWebsiteinfo(Websiteinfo websiteinfo) {
        int row = websiteInfoMapper.insertStatisticsVisit(websiteinfo);
        return row;
    }


    @Override
    public Websiteinfo selectInfoById(Long id) {
        Websiteinfo websiteinfo = websiteInfoMapper.selectWebsiteInfoById(String.valueOf(id));
        return websiteinfo;
    }


    @Override
    public int updateWebsiteinfo(Websiteinfo websiteinfo) {
        return websiteInfoMapper.updateWebsiteinfo(websiteinfo);
    }
}
